<template>
	<view class="page">
		<!-- <view class="selectBox">
			<view class="selectItem" @click="handleSelectItem(index)">
				<view class="selectRow">
					<view class="className">
						{{item.courseId_dictText}}
					</view>
					<text class="moneyText red">￥{{item.money}}</text>
				</view>
			</view>
		</view> -->
		<view class="container">
			<view class="rowTitle">{{'课程详情'}}</view>
			<view class="row"  v-for="(item,index) in selectClassArr" :key="index">
			  <view class="label">{{item.courseId_dictText}}：</view>
			  <text class="text money red">￥{{item.money}}</text>
			</view>
		</view>	
			
		<view class="row">
			<view class="label">
				{{'合计'}}:
			</view>
			<view class="text money red" style="font-weight: 600;">
				￥{{totalMoney}}
			</view>
		</view>
		
		<view class="textTitle">
			{{language.topup.label4}}
		</view>
		<view class="payType">
			<u-icon name="weixin-fill" color="#10d269" size="30"></u-icon>
			<text>
				{{language.topup.label5}}
			</text>
			<u-icon name="checkmark" color="#2979ff" size="28"></u-icon>
		</view>
		<view class="btn" @click="handleTopup">
			<text>{{'支付'}}</text>
		</view>
		
	</view>
</template>

<script>
	import { csCoursePayOrderDetailListApi,csCoursePayOrderPaymentApi} from '@/common/api/commonApi/bugClass.js'
	export default {
		data() {
			return {
				selectClassArr:[
					// {
					// 	checked: true,
					// 	label : '美术绘画',
					// 	tip: '选交',
					// 	num: '不限',
					// 	money: 150
					// },
				],
				selectMoney: '',
				deductionAmount: '',
				serviceCharge :'',
				cardSn : '',
				selectInfoAccount : uni.getStorageSync('selectInfoAccount'),
				id :'',
				subjectIdList : [],
				payBool: false,
				
			}
		},
		computed: {
			totalMoney(){
				let num = 0
				this.selectClassArr.forEach(item=>{
						num+=item.money
				})
				return num
			}
		},
		methods: {
			handleSelectItem(index){
				console.log(this.selectClassArr[index]);
				let item = this.selectClassArr[index]
				item.checked = !item.checked
				this.$set(this.selectClassArr,index,item)
			},
			getList(){
				return csCoursePayOrderDetailListApi({
					 payId : this.id
				}).then(res=>{
					this.selectClassArr = res.result.records
				})
			},
			handleTopup(){
				if(!this.totalMoney) return this.setMessage('请先选择课程')
				let data = {
					payId : this.id,
				}
				if(this.payBool) return
				this.payBool = true
				csCoursePayOrderPaymentApi(data).then(res=>{
						uni.requestPayment({
							provider: 'wxpay',
							nonceStr :  res.result.nonce_str,
							package : `prepay_id=${res.result.prepay_id}`,
							paySign : res.result.sign,
							signType : 'MD5',
							timeStamp: String(res.result.timeStamp),
							success:() =>{
									this.setMessage('支付成功')
									setTimeout(()=>{
										uni.reLaunch({
											url:'/pages/index/index'
										})
									},1000)
							},
							fail: (err) => {
								console.log(err);
								this.setMessage('支付取消或失败')
							},
							// complete:()=> {
							// 	this.payBool = false
							// }
						})
				
				}).complete(res=>{
					this.payBool = false
				})
			}
		},
		onLoad({id}) {
			this.id = id
			this.getList()
		
		},
		onShow() {
			
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #fff;
	height: 100vh;
	.text{
		color: #333;
	}
	.row{
		display: flex;
		align-items: center;
		height: 90rpx;
		border-bottom: 2rpx solid #f1f1f1;
		&:nth-child(1){
			border-top: 2rpx solid #f1f1f1;
		}
		.label{
			margin: 0 30rpx;
		}
	
	}
	.red{
		color: #fe415c;
	}
	.money{
		height: 100rpx;
		@include flexCenter;
		font-size: 36rpx;
		border-bottom: 2rpx solid #f1f1f1;
		text{
			font-size: 28rpx;
			color: #333;
			margin-left: 5rpx;
		}
	}
	.textTitle{
		margin-top: 40rpx;
		font-size: 30rpx;
		padding-left: 50rpx;
		color: #000;
	}
	.rowTitle {
	    padding: 20rpx;
	    margin: 0 30rpx;
	    position: relative;
	    border-top: 2rpx solid #e6e6e6;
	}
	.payType{
		display: flex;
		align-items: center;
		height: 110rpx;
		padding: 0 50rpx;
		width: 100%;
		image{
			width: 50rpx;
			height: 60rpx;
		}
		text{
			color: #000;
			flex: 1;
			padding-left: 20rpx;
			white-space: nowrap;
			font-size: 30rpx;
		}
	}
	.btn{
		margin: 20rpx auto 0;
		background: #2d8cf6;
		@include flexCenter;
		width: 90vw;
		height: 92rpx;
		border-radius: 10rpx;
		text{
			color: #fff;
		}
	}
	
	

	.tipBtn{
		color: #0072e5;
		padding:  5rpx 10rpx;
		border: 2rpx solid #0072e5;
		border-radius: 10rpx;
	}
	
	.container {
	    background-color: #fff;
		// padding-bottom: 50rpx;
		
	}
	.row {
	    width: 100%;
	    padding: 20rpx 20rpx;
	    display: flex;
	    align-items: center;
	    /* border-top: 2rpx solid #e6e6e6; */
	}
}
</style>
